home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qptrdict.h.z / qptrdict.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  6.2 KB  |  165 lines

  1. /****************************************************************************
  2. ** $Id: qptrdict.h,v 1.5 1998/07/03 00:09:46 hanord Exp $
  3. **
  4. ** Definition of QPtrDict template/macro class
  5. **
  6. ** Created : 970415
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QPTRDICT_H
  25. #define QPTRDICT_H
  26.  
  27. #ifndef QT_H
  28. #include "qgdict.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QPtrDictdeclare QPtrDictMdeclare
  43. #define QPtrDict QPtrDictM
  44. #endif
  45. #define QPtrDictM(type) name2(QPtrDictM_,type)
  46.  
  47. #define QPtrDictMdeclare(type)                              \
  48. class QPtrDictM(type) : public QGDict                          \
  49. {                                          \
  50. public:                                          \
  51.     QPtrDictM(type)(int size=17):QGDict(size,0,0,TRUE) {}              \
  52.     QPtrDictM(type)( const QPtrDictM(type) &d ) : QGDict(d) {}              \
  53.    ~QPtrDictM(type)()        { clear(); }                      \
  54.     QPtrDictM(type) &operator=(const QPtrDictM(type) &d)              \
  55.             { return (QPtrDictM(type)&)QGDict::operator=(d); }    \
  56.     uint  count()   const    { return QGDict::count(); }              \
  57.     uint  size()    const    { return QGDict::size(); }              \
  58.     bool  isEmpty() const    { return QGDict::count() == 0; }          \
  59.     void  insert( void *k, const type *d )                      \
  60.                 { QGDict::look((const char*)k,(GCI)d,1); }    \
  61.     void  replace( void *k, const type *d )                      \
  62.                 { QGDict::look((const char*)k,(GCI)d,2); }    \
  63.     bool  remove( void *k )    { return QGDict::remove((const char*)k); }    \
  64.     type *take( void *k )    { return (type*)QGDict::take((const char*)k);}\
  65.     void  clear()        { QGDict::clear(); }                  \
  66.     void  resize( uint n )    { QGDict::resize(n); }                  \
  67.     type *find( void *k )    const                          \
  68.     { return (type *)((QGDict*)this)->QGDict::look((const char*)k,0,0);}  \
  69.     type *operator[]( void *k ) const                          \
  70.     { return (type *)((QGDict*)this)->QGDict::look((const char*)k,0,0);}  \
  71.     void  statistics() const    { QGDict::statistics(); }              \
  72. private:                                      \
  73.     void  deleteItem( GCI d )    { if ( del_item ) delete (type *)d; }          \
  74. }
  75.  
  76.  
  77. #if defined(DEFAULT_MACROCLASS)
  78. #define QPtrDictIteratordeclare QPtrDictIteratorMdeclare
  79. #define QPtrDictIterator QPtrDictIteratorM
  80. #endif
  81. #define QPtrDictIteratorM(type) name2(QPtrDictIteratorM_,type)
  82.  
  83. #define QPtrDictIteratorMdeclare(type)                          \
  84. class QPtrDictIteratorM(type) : public QGDictIterator                  \
  85. {                                          \
  86. public:                                          \
  87.     QPtrDictIteratorM(type)(const QPtrDictM(type) &d) :                  \
  88.     QGDictIterator((QGDict &)d){}                          \
  89.    ~QPtrDictIteratorM(type)()     {}                          \
  90.     uint  count()   const     { return dict->count(); }                  \
  91.     bool  isEmpty() const     { return dict->count() == 0; }              \
  92.     type *toFirst()          { return (type *)QGDictIterator::toFirst(); }   \
  93.     operator type *()  const  { return (type *)QGDictIterator::get(); }          \
  94.     type *current()    const  { return (type *)QGDictIterator::get(); }          \
  95.     void *currentKey() const  { return (void *)QGDictIterator::getKey(); }    \
  96.     type *operator()()          { return (type *)QGDictIterator::operator()(); }\
  97.     type *operator++()          { return (type *)QGDictIterator::operator++(); }\
  98.     type *operator+=(uint j)  { return (type *)QGDictIterator::operator+=(j);}\
  99. }
  100.  
  101. #endif // USE_MACROCLASS
  102.  
  103.  
  104. #if defined(USE_TEMPLATECLASS)
  105.  
  106. #if defined(DEFAULT_TEMPLATECLASS)
  107. #undef    QPtrDict
  108. #define QPtrDict QPtrDictT
  109. #endif
  110.  
  111. template<class type> class QPtrDictT : public QGDict
  112. {
  113. public:
  114.     QPtrDictT(int size=17) : QGDict(size,0,0,TRUE) {}
  115.     QPtrDictT( const QPtrDictT<type> &d ) : QGDict(d) {}
  116.    ~QPtrDictT()            { clear(); }
  117.     QPtrDictT<type> &operator=(const QPtrDictT<type> &d)
  118.             { return (QPtrDictT<type>&)QGDict::operator=(d); }
  119.     uint  count()   const    { return QGDict::count(); }
  120.     uint  size()    const    { return QGDict::size(); }
  121.     bool  isEmpty() const    { return QGDict::count() == 0; }
  122.     void  insert( void *k, const type *d )
  123.                 { QGDict::look((const char*)k,(GCI)d,1); }
  124.     void  replace( void *k, const type *d )
  125.                 { QGDict::look((const char*)k,(GCI)d,2); }
  126.     bool  remove( void *k )    { return QGDict::remove((const char*)k); }
  127.     type *take( void *k )    { return (type*)QGDict::take((const char*)k); }
  128.     void  clear()        { QGDict::clear(); }
  129.     void  resize( uint n )    { QGDict::resize(n); }
  130.     type *find( void *k )    const
  131.     { return (type *)((QGDict*)this)->QGDict::look((const char*)k,0,0); }
  132.     type *operator[]( void *k ) const
  133.     { return (type *)((QGDict*)this)->QGDict::look((const char*)k,0,0); }
  134.     void  statistics() const    { QGDict::statistics(); }
  135. private:
  136.     void  deleteItem( GCI d )    { if ( del_item ) delete (type *)d; }
  137. };
  138.  
  139.  
  140. #if defined(DEFAULT_TEMPLATECLASS)
  141. #undef    QPtrDictIterator
  142. #define QPtrDictIterator QPtrDictIteratorT
  143. #endif
  144.  
  145. template<class type> class QPtrDictIteratorT : public QGDictIterator
  146. {
  147. public:
  148.     QPtrDictIteratorT(const QPtrDictT<type> &d) :QGDictIterator((QGDict &)d) {}
  149.    ~QPtrDictIteratorT()          {}
  150.     uint  count()   const     { return dict->count(); }
  151.     bool  isEmpty() const     { return dict->count() == 0; }
  152.     type *toFirst()          { return (type *)QGDictIterator::toFirst(); }
  153.     operator type *()  const  { return (type *)QGDictIterator::get(); }
  154.     type *current()    const  { return (type *)QGDictIterator::get(); }
  155.     void *currentKey() const  { return (void *)QGDictIterator::getKey(); }
  156.     type *operator()()          { return (type *)QGDictIterator::operator()(); }
  157.     type *operator++()          { return (type *)QGDictIterator::operator++(); }
  158.     type *operator+=(uint j)  { return (type *)QGDictIterator::operator+=(j);}
  159. };
  160.  
  161. #endif // USE_TEMPLATECLASS
  162.  
  163.  
  164. #endif // QPTRDICT_H
  165.